<?php


namespace App\Models;
use App\Services\Api\EsService;
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
use Elasticsearch\ClientBuilder;
/**
 * FontAwesome
 * created on 2020/7/29 15:28
 * created by chengzhigang
 */
class FontAwesome extends Model
{
    use Searchable;

    protected $table = 'font_awesome';
    private $EsClient;
    private $index = 'myapp';
    private $type = 'font';
    public $timestamps = false;
    protected $fillable = [
        'name','desc'
    ];

    /**
     * 定义索引里的type值,重写
     * @return string
     */
    public function searcheableAs()
    {
        return "font";
    }

    /**
     * 定义那些字段需要搜索
     * @return array
     */
    public function searchableArray()
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'desc' => $this->desc,
            'create_time'=>$this->create_time
        ];
    }

//    public static function search($filter,$page=1,$per_page=10,$sort='create_time',$order="desc"){
//        $params = [
//            'index' => 'myapp',
//            'body' => [
//                'from'  => $page-1,
//                'size'  => $per_page,
//                'query' => [
//                    'multi_match' => [
//                        'query' => $filter,
//                        'fields' => ['name','desc']
//                    ]
//                ],
//                'sort'  => [
//                    $sort.".keyword"  => [
//                        "order" => $order
//                    ]
//                ]
//            ]
//        ];
//        $esService = new EsService('myapp');
//        return $esService -> search($params);
//    }

    public static function getDoc(){
        $esService = new EsService('myapp');
        return $esService -> getDoc(['index'=>'myapp','type'=>'_doc','id'=>22]);
    }

}
